﻿using FluentValidation;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace ZFB.DTO.FluentValidation
{
        public class LoginValidetor : AbstractValidator<LoginDTO>
        {
            public LoginValidetor()
            {
                RuleFor(e => e.phoneNum).NotEmpty().WithMessage("手机号不能为空").Must(IsMobile).WithMessage("手机号格式不正确");
            RuleFor(x => x.password).NotEmpty().WithMessage("密码不能为空");



            }
            private bool EncryptionPassword(string password)
            {
                //正则
                var regex = new Regex(@"
                            (?=.*[0-9]) 
                            (?=.*[a-zA-Z])  
                            (?=([\x21-\x7e]+)[^a-zA-Z0-9])  
                            .{6,16}", RegexOptions.Multiline | RegexOptions.IgnorePatternWhitespace);
                return regex.IsMatch(password);
            }
            private bool IsMobile(string arg)
            {
                return Regex.IsMatch(arg, @"^[1][3-8]\d{9}$");
            }

        }
}
